<?php

/**
 * Framework_Component_UserNav
 *
 * @author      Ian Szewczyk <roamzero@gmail.com>
 * @copyright   (c) 2007 Ian Szewczyk. All rights reserved.
 * @license http://www.opensource.org/licenses/bsd-license.php
 * @package Framework
 * @subpackage Component
 * @filesource
 */

/**
 * Framework_Component_UserNav
 *
 *
 * @author Ian Szewczyk <roamzero@gmail.com>
 * @package Framework
 * @subpackage Component
 */

class Framework_Component_UserNav extends Framework_Component_Common
{


	/**
	 * __construct
	 *
	 * @access 		public
	 * @param 		array		$params		Parameters passed from template
	 * @return 		void
	 */
	public function __construct($params = null)
	{
		parent::__construct($params);
		
		$this->tplFile = null;
	}

	/**
	 * run
	 *
	 * @access 		public
	 * 
	 * @return 		void
	 */
	public function run()
	{
		// Use Navigator class
		$navigator = new Framework_Navigator('','topTabs');
		if ($this->user->userStatus == ANONYMOUS_USER_STATUS) {
			$navigator->setItem('ownerLogin','/-/User/Login','Owner Login');
		} else if ($this->user->userStatus == NORMAL_USER_STATUS || $this->user->userStatus == OWNER_USER_STATUS) {
			$navigator->setItem('ownerLogout','/-/User/Logout','Logout');
		}
		
		$meta = Framework_Meta::factory();
		$metaTable = $meta->getTable();
		
		$queryArray = array(
			'sqlKey' => array(
				'select' => 'idMetaModule, moduleAlias',
				'where'  => 'moduleActive = 1 
                             AND moduleCategory = "Site" 
                             AND idMetaModule != "User"'
			)
		);
		
		$result = $metaTable->select($queryArray);
		
		if (!PEAR::isError($result) && count($result)) {
			
			foreach ($result as $row) {
				if ($this->user->userStatus == ANONYMOUS_USER_STATUS && $row['idMetaModule'] == 'Register') {
					$navigator->setItem( $row['idMetaModule'] ,'/-/'.$row['idMetaModule'], $row['moduleAlias']);
				} else  {
					$navigator->setItem( $row['idMetaModule'] ,'/-/'.$row['idMetaModule'], $row['moduleAlias']);
				}
			}
			
		}
		$navigator->setActive(Framework::$request->module);
		$this->setData('nav',$navigator->getNavigation());
   }
}

?>